其他
CTO:不要在 Java 代码中写 set/get 方法了,逮一次罚款***
这里是码农充电第一站,回复“666”,获取一份专属大礼包 真爱,请设置“星标”或点个“在看”
前言 Lombok背景介绍 Lombok使用方法
前言
Lombok背景介绍
Lombok使用方法
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.10</version>
<scope>provided</scope>
</dependency>
将 Lombok 插件安装到 IDEA
选择默认的编译方式为 javac,因为 eclipse 是不支持 Lombok 的编译方式的,javac 支持 Lombok 的编译方式。
打开注解生成器 Enable annotation processing
public class Student {
private String name;
private Integer age;
private Integer id;
private String major;
}
@Setter private String name;
private Integer age;
private Integer id;
private String major;
public static void main(String[] args) {
Student stu = new Student();
stu.setName("Mr.ml");
}
}
@Setter private String name;
private Integer age;
private Integer id;
private String major;
public Student(@NonNull String name) {
this.name = name;
}
}
public static void main(String[] args) throws IOException {
@Cleanup InputStream in = new FileInputStream(args[0]);
@Cleanup OutputStream out = new FileOutputStream(args[1]);
byte[] b = new byte[10000];
while (true) {
int r = in.read(b);
if (r == -1) break;
out.write(b, 0, r);
}
}
}
public class EqualsAndHashCodeExample {
private transient int transientVar = 10;
private String name;
private double score;
private Shape shape = new Square(5, 10);
private String[] tags;
private int id;
public String getName() {
return this.name;
}
@EqualsAndHashCode(callSuper=true)
public static class Square extends Shape {
private final int width, height;
public Square(int width, int height) {
this.width = width;
this.height = height;
}
}
}
public class ToStringExample {
private static final int STATIC_VAR = 10;
private String name;
private Shape shape = new Square(5, 10);
private String[] tags;
private int id;
public String getName() {
return this.getName();
}
@ToString(callSuper=true, includeFieldNames=true)
public static class Square extends Shape {
private final int width, height;
public Square(int width, int height) {
this.width = width;
this.height = height;
}
}
}
@AllArgsConstructor(access = AccessLevel.PROTECTED)
public class ConstructorExample<T> {
private int x, y;
@NonNull private T description;
@NoArgsConstructor
public static class NoArgsExample {
@NonNull private String field;
}
}
---END--- 重磅!鱼哥微信好友坑位限时开放啦!
福利来啦!扫码直接加鱼哥微信号,送你一份刷题指南和面试手册,不仅可以围观鱼哥平时所思和复盘的内容。还可以帮你免费内推大厂,技术交流,一起探索职场突围,收入突围,技术突围。一定要备注:开发方向+地点+学校/公司+昵称(如Java开发+上海+拼夕夕+猴子)
▲长按加鱼哥微信,赶紧上车
福利来啦!扫码直接加鱼哥微信号,送你一份刷题指南和面试手册,不仅可以围观鱼哥平时所思和复盘的内容。还可以帮你免费内推大厂,技术交流,一起探索职场突围,收入突围,技术突围。一定要备注:开发方向+地点+学校/公司+昵称(如Java开发+上海+拼夕夕+猴子)